<template>
    <div class="check">
        <dialog-kan-ban-details v-model="taskList"></dialog-kan-ban-details>
    </div>
</template>

<script>
    import DialogKanBanDetails from '../../components/dialogModel/KanBanDetails.vue';
    export default {
        name: 'order-detail',
        props: {
            params: {
                type: Object,
                default: () => {
                    return {}
                }
            }
        },
        components: {
            DialogKanBanDetails
        },
        data() {
            return {
                taskList:{
                    date: '2018-12-05',
                    task: [],
                    kanBanDetailData: {}
                }
            }
        },
        created() {
            this.getNowFormatDate();
            this.getOrderDetail();
            this.getTaskDetail();
        },
        computed: {
            dataRefreshEvents() {
                return this.$store.state.num;
            },
            id: function (value) {
                return this.params.id
            },
            changeDate: function (val) {
                return this.taskList.date;
            }
        },
        watch: {
            dataRefreshEvents: function () {
                this.getOrderDetail();
                this.getTaskDetail();
            },
            changeDate: function (val) {
                this.getTaskDetail();
            }
        },
        methods: {
            getNowFormatDate() {
                let date = new Date();
                let seperator = "-";
                let year = date.getFullYear();
                let month = date.getMonth() + 1;
                let strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                let currentdate = year + seperator + month + seperator + strDate;
                this.taskList.date = currentdate;
            },
            getOrderDetail() {
                this.$http.get('user/driver/' + this.id)
                    .then((response) => {
                        this.taskList.kanBanDetailData = response.data.data;
                    })
                    .catch((error) => {
                        if(error.response.data.msg){
                            this.$message.error(error.response.data.msg);
                        }else{
                            this.$message.error('请求错误：'+error.response.status);
                        }
                    });
            },
            getTaskDetail() {
                this.$http.get('user/driver/mission?user_id=' + this.id + '&date=' + this.changeDate + '&pageSize=200')
                    .then((response) => {
                        this.taskList.task = response.data.data;
                    })
                    .catch((error) => {
                        if(error.response.data.msg){
                            this.$message.error(error.response.data.msg);
                        }else{
                            this.$message.error('请求错误：'+error.response.status);
                        }
                    });
            }
        }
    }
</script>

<style scoped>

</style>
